const jwt = require('jsonwebtoken');
const serect = 'token';  //密钥，不能丢
const token = {
  // 添加token
  addToken(userinfo) {
    const token = jwt.sign({
      id: userinfo.id
    }, serect, {expiresIn: '1h'})
    return token
  },
  //验证token
  proving(tokens) {
    if (tokens) {
      // 解析
      let decoded = jwt.decode(tokens, serect)
      return decoded
    } else {
      return null
    }
  }
}
module.exports = token
